
import java.util.HashMap;
import java.util.Map;

/**
 * {@link Solution1218 }
 */
public class Solution1218 {
    public static int longestSubsequence(int[] arr, int difference) {
        int ans = 1;
        Map<Integer, Integer> map = new HashMap<>();
        for (int i : arr) {
            int temp = map.getOrDefault(i - difference, 0) + 1;
            map.put(i, temp);
            ans = Math.max(ans, temp);
        }
        return ans;
    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4};

        System.out.println(longestSubsequence(arr, 1));
    }
}
